package com.chum.chamber.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.support.SessionStatus;

import com.chum.chamber.model.RegisteredCase;
import com.chum.chamber.service.RegisteredCaseService;
import com.chum.chamber.validator.RegisteredCaseValidator;

@Controller
@RequestMapping("/registeredCase.htm")
public class RegisteredCaseController {

	RegisteredCaseValidator registeredCaseValidator;
	RegisteredCaseService registeredCaseService; 
	
	@Autowired
	public RegisteredCaseController(RegisteredCaseValidator registeredCaseValidator, RegisteredCaseService registeredCaseService) {
		this.registeredCaseValidator = registeredCaseValidator;
		this.registeredCaseService = registeredCaseService;
	}
	
	@RequestMapping(method = RequestMethod.POST)
	public String registeredCaseSubmit(@ModelAttribute("registeredCase")RegisteredCase registeredCase, BindingResult result, SessionStatus status) {
		
		return "RegisteredCaseForm";
	}
	
	@RequestMapping(method = RequestMethod.GET)
	public String initForm(ModelMap model){
		RegisteredCase registeredCase = new RegisteredCase();
		registeredCase.setGridView(registeredCaseService.getRegisteredCaseList());
		model.addAttribute("gridView", registeredCase.getGridView());
		model.addAttribute("registeredCase", registeredCase);
		return "RegisteredCaseForm";
	}
}
